package com.jbit.dm_160.service.impl;

import com.jbit.dm_160.mapper.ItemTypeMapper;
import com.jbit.dm_160.model.dto.FloorItemDTO;
import com.jbit.dm_160.model.dto.FloorTypeDTO;
import com.jbit.dm_160.model.dto.ItemDTO;
import com.jbit.dm_160.model.dto.ItemTypeDTO;
import com.jbit.dm_160.service.ItemService;
import com.jbit.dm_160.service.ItemTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ItemTypeServiceImpl implements ItemTypeService {
    @Resource
    private ItemTypeMapper itemTypeMapper;
    @Resource
    private ItemService itemService;
    @Override
    public List<ItemTypeDTO> list() {
        List<ItemTypeDTO> list = itemTypeMapper.getFirst();
        for (ItemTypeDTO itemTypeDTO : list) {
            List<ItemTypeDTO> childList = itemTypeMapper.getChild(itemTypeDTO.getId());
            List<ItemDTO> itemList = itemService.getItemByType1Id(itemTypeDTO.getId());
            itemTypeDTO.setChildren(childList);
            itemTypeDTO.setHotItems(itemList);
        }
        return list;
    }

    @Override
    public List<ItemTypeDTO> getFirst() {
        return itemTypeMapper.getFirst();
    }

    @Override
    public List<FloorTypeDTO> getFloor() {
        List<FloorTypeDTO> floorDTOList = itemTypeMapper.getFloor();
        for (FloorTypeDTO floorDTO : floorDTOList) {
            List<FloorItemDTO> itemDTOList = itemService.getItemsByFloor(floorDTO.getItemTypeId());
            floorDTO.setItems(itemDTOList);
        }
        return floorDTOList;
    }

    @Override
    public List<ItemTypeDTO> getTypesByParent(Integer parent) {
        return itemTypeMapper.getChild(parent);
    }
}

